#include "paintinglabel.h"
#include <common/settings.h>
#include <common/constants.h>

#include <QToolTip>
#include <QRect>

#include <QDebug>

using namespace Constants;

PaintingLabel::PaintingLabel(QWidget * parent):m_curse(0),m_frame(0),m_scrollarea(0)
{
    setMouseTracking(true);
    //resize(parent->size());
    m_scrollarea = parent;    
    m_frame = parent->parentWidget();
    m_curse = m_frame->parentWidget();   
    settings set(this);
    m_heightmultiplicator = set.value(Constants::Y_MULTIPLIER).toFloat();
    setText("HELLO");
    m_bmiManager = new BmiManager(this);
    m_modelBmi = new QStandardItemModel;
}


PaintingLabel::~PaintingLabel(){}

void PaintingLabel::getZoomAndSex(int zoom, QString sex)
{
    m_zoom = zoom;
    m_sex = sex;
    if (m_sex.contains("F"))
    {
    	  m_modelBmi = m_bmiManager->getBmiFemale();
    	  qWarning() << __FILE__ << QString::number(__LINE__) << " FEMALE " ;
        }
    if(m_sex.contains("M"))
    {
          m_modelBmi = m_bmiManager->getBmiMale();
          qWarning() << __FILE__ << QString::number(__LINE__) << " MALE " ;
        }
    m_yReducing = m_modelBmi->data(m_modelBmi->index(0,SD_AVERAGE_SD),Qt::DisplayRole).toFloat();
}

void PaintingLabel::mouseMoveEvent(QMouseEvent * event)
{
    int zoom = m_zoom;
    int xMouse = event->x();
    int yMouse = event->y();
    int xWidget = width();
    int yWidget = height();    
    float x = float(xMouse / zoom );
    float y = float(yMouse/zoom); 
    float bmi = ((yWidget - yMouse)/zoom)/m_heightmultiplicator + m_yReducing;
    QString text = QString("bmi = %1").arg(QString::number(bmi));
    QToolTip::showText ( QPoint(x,y), text, this, QRect(0,0,xWidget,yWidget) );
}


